﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Swork03_28.Api.Application.Commands.SlaughterCommand;
using Swork03_28.Domain.TraceableInfos;
using System.Security.Claims;

namespace Swork03_28.Api.Controllers
{
    /// <summary>
    /// 屠宰控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class SlaughtersController : ControllerBase
    {
        private readonly IMediator mediator;

        public SlaughtersController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加屠宰信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> SlaughterCreate(SlaughterCreateCommand command)
        {
            var UserId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            command.UserId = int.Parse(UserId);
            return await mediator.Send(command);
        }

        /// <summary>
        /// 获取屠宰信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Slaughter> GetSlaughter([FromQuery] SlaughterSelectCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 添加屠宰资质图片
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> CertificationCreate([FromQuery] CertificationCreateCommand command)
        {
            return await mediator.Send<int>(command);
        }

        /// <summary>
        /// 删除屠宰资质
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> CertificationDel([FromQuery] CertificationDelCommand command)
        {
            return await mediator.Send<int>(command);
        }

        /// <summary>
        /// 添加屠宰公司信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> FirmCrates(FirmsCreateCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 添加屠宰公司信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> FirmImgCrates([FromQuery] FirmImgsCreateCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 获取屠宰公司信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<FirmInfo> GetFirmInfo([FromQuery]FirmSelectsCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 删除屠宰公司图片
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> FirmImgDel([FromQuery]FirmImgDelCommand command)
        {
            return await mediator.Send(command);
        }
    }
}
